package com.gitee.wsl.common.ui.input.event

import com.gitee.wsl.mathematics.interpolator.Percent
import com.gitee.wsl.mathematics.interpolator.pct

/**
 * A generic chart event.
 */
 interface ChartEvent : KEvent {

    /**
     * The preventDefault variable of the ChartEvent interface tells the Chart that its default action should not
     * be taken as it normally would be.
     *
     * For example if you want to completely override the selection behavior of a chart, just put some
     * onSelect listener, do the stuff you want to do and set event.preventDefault to true.
     */
     var preventDefault: Boolean
}

/**
 * A "pan event" is triggered when a user move the viewport of a [Chart].
 *
 * @param panX The translation along the X-axis in [Percent].
 * @param panY The translation along the Y-axis in [Percent].
 */
 class PanEvent( val panAction: PanAction) : ChartEvent {
     constructor(panX: Percent, panY: Percent) : this(PanAction(panX, panY))

    override var preventDefault: Boolean = false
}

internal operator fun PanAction.plus(other: PanAction): PanAction =
    PanAction(panX + other.panX, panY + other.panY)

/**
 * A pan action from chart-relative coordinates, defaults to 0% / 0% (no pan).
 */
 data class PanAction(
    val panX: Percent = 0.pct,
    val panY: Percent = 0.pct
) {
     fun constraintOnX(): PanAction = PanAction(0.pct, panY)
     fun constraintOnY(): PanAction = PanAction(panX, 0.pct)
}